<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>签到列表</title>
		<link rel="stylesheet" type="text/css" href="../css/api.css"/>
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/base.css">
		<link rel="stylesheet" href="../../css/weui.min.css">
		<style>
			body {
			}
			.mui-table-view-cell > a:not(.mui-btn) {
				padding: 10px;
			}
			.cell-title {
				height: 22px;
			}
			.cell-subtitle, .message_content {
				height: 20px;
			}
			.right-div {
				width: 70px;
				float: right;
			}
			.left-div {
				margin-right: 70px;
			}
			.message_title {
				width: 90%;
				color: #222222;
			}
			.right-tag {
				text-align: right;
				height: 20px;
			}
			.mui-table-view .mui-media-object {
				/*margin-top: 10px;*/
			}
			.discuss-del {
				width: 18px;
				margin-right: 0px;
			}
			.discuss-del-div {
				text-align: right;
				height: 24px;
				padding-top: 4px;
			}
			.statesImg {
				width: 20px;
				height: 20px;
				float: left;
			}
			.mui-backdrop {
				position: fixed;
				top: 0;
				right: 0;
				bottom: 0;
				left: 0;
				z-index: 998;
				background-color: rgba(0,0,0,.3);
				display: none;
			}
			.popu_img {
				height: 20px;
				width: 20px;
			}
		</style>
	</head>
	<body>
		<div id="mian">
			<ul id="SignList" class="mui-table-view">
				<!-- <li class="mui-table-view-cell mui-media" where_type="0" id="7040" onclick="openwin(this,{&quot;template&quot;:1,&quot;id&quot;:7040,&quot;name&quot;:&quot;签到-20180806033&quot;,&quot;num&quot;:0,&quot;countnum&quot;:0,&quot;tid&quot;:1,&quot;createtime&quot;:&quot;1533544995&quot;,&quot;status&quot;:0})"><a href="javascript:;"><img class="mui-media-object mui-pull-left" src="../../image/icon_qiandao_.png" ><div class="mui-media-body"><div class="right-div"><div class="discuss-del-div"><img class="popu_img" src="../../image/icon_bewrite_down.png" onclick="openPopu(0,0,{&quot;template&quot;:1,&quot;id&quot;:7040,&quot;name&quot;:&quot;签到-20180806033&quot;,&quot;num&quot;:0,&quot;countnum&quot;:0,&quot;tid&quot;:1,&quot;createtime&quot;:&quot;1533544995&quot;,&quot;status&quot;:0})"></div><p class="mui-ellipsis base_grey content_p right-tag font12 ">未开始</p></div><div class="left-div"><p class="mui-ellipsis base_dark_grey font14 cell-title"><span class="message_title">签到-20180806033</span></p><p class="mui-ellipsis base_grey font14 content_p cell-subtitle"><span class="file_submit_time">2018-08-06 16:43</span></p></div></div></a></li> -->
			</ul>
		</div>
		<div class="noSign" hidden="hidden" id="noData">
			<img src="../../image/icon_img.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				暂无数据
			</p>
		</div>
		<div class="loadFailure" hidden="hidden" id="noNet">
			<img src="../../image/icon_img01.png" width="60%">
			<p class="" >
				数据加载失败
			</p>
			<p>
				请检查您的网络
			</p>
			<button type="button"  onclick="loadNewData()" class="mui-btn mui-btn-outlined">
				重新加载
			</button>
		</div>
		<div id="logout" class="weui_dialog_confirm" style="display: none;">
			<div class="weui_mask"></div>
			<div class="weui_dialog">
				<div class="weui_dialog_hd">
					<strong class="weui_dialog_title">是否确定删除签到？</strong>
				</div>
				<div class="weui_dialog_ft">
					<a href="javascript:cancel();" class="weui_btn_dialog default" style="color:#18b4ed">取消</a>
					<a  href="javascript:confirm();" class="weui_btn_dialog primary" style="color:#18b4ed">确定</a>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/timeStampTool.js"></script>
	<script src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/activityBottomPopup.js"></script>
	<script type="text/javascript">
		var page = 1;
		var row = 10;
		var refreshCount = 0;
		var tid = '';
		//当前点击的数据库中的tid
		var dataSource = [];
		var firstLoad = true;
		//存储全局数据
		var apiready = function() {
			loadNewData();
			setRefreshHeader();
			setPullUpRefresh();
			receNotifi();
			sendBuriedNotifi('0', '老师端签到列表', '193')
		};
		function sendBuriedNotifi(busionessid, pagetype, pagetypeid) {
			var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				uname : $api.getStorage('cfnetppusername'),
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl : window.location.pathname,
				accesspagetitle : document.title,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}

		//接受通知
		function receNotifi() {
			api.addEventListener({
				name : 'scroolToTop'
			}, function(ret, err) {
				$('html,body').animate({
					scrollTop : '0px'
				}, 200);
			});
			api.addEventListener({
				name : 'reloadDataList'
			}, function(ret, err) {
				loadNewData();
			});
			api.addEventListener({
				name : 'pushMessage_classroomMessage'
			}, function(ret, err) {
				var notifiJid = ret.value.jid;
				if (notifiJid == $api.getStorage('cfnetppjxid')) {
					var QD_TYPE = ret.value.type;
					if (QD_TYPE == 10009) {
						loadNewData();
					}
				}
			});
		}

		function loadNewData() {
			showProgress();
			dataSource = [];
			firstLoad = true;
			page = 1;
			loadData();
		}

		function loadMoreData() {
			page++;
			loadData();
		}

		//获取数据
		function loadData() {
			if (firstLoad == true) {
				showProgress();
				firstLoad = false;
			}
			var params = {
				jid : $api.getStorage('cfnetppjxid'),
				uid : $api.getStorage('cfnetppuid'),
				tid : 1,
				cid : api.pageParam.cid,
				pid : api.pageParam.pid,
				page : page,
				rows : row
			};
			cfnetppPOST(url_activeList, params, true, function(data, status) {
				api.hideProgress();
				api.refreshHeaderLoadDone();
				if (status == 'success') {
					if (data.code == 200) {
						var listdata = data.data;
						if (listdata != '' && listdata.constructor == Array && listdata.length > 0) {
							$('#noData').hide();
							$('#noNet').hide();
							$('#mian').show();
							refreshCount = listdata.length;
							writelist(listdata, refreshCount);
							// alert(JSON.stringify(listdata));
							for (var i = 0; i < refreshCount; i++) {
								dataSource.push(listdata[i]);
							}
						}
					} else if (data.code == 108) {
						if (page == 1) {
							$('#noNet').hide();
							$('#noData').show();
							$('#mian').hide();
						}
					} else if (data.code == 101) {
						api.toast({
							msg : '参数错误',
							duration : 2000,
							location : 'bottom'
						});
					}
				} else {
					if (page == 1) {
						$('#noData').hide();
						$('#noNet').show();
						$('#mian').hide();
					}
				}
			});
		}

		function writelist(listdata, len) {
			var index = dataSource.length;
			var writelist = '';
			for (var i = 0; i < len; i++) {
				var data = listdata[i];
				var type = data.status;
				var delethtml = '';
				var status = '';
				var xiabiao = index + i;
				var name = '';
				if (data.name == "" || data.name == null) {
					name = '';
				} else {
					name = data.name;
				}
				var classname = '';
				if (data.classname == "" || data.classname == null) {
					classname = '';
				} else {
					classname = data.classname;
				}
				var DataArr = JSON.stringify(data).replace(/"/g, '&quot;');
				if (type == 0) {//未开始
					status = '未开始';
					delethtml = '<img class="popu_img" src="../../image/icon_bewrite_down.png" onclick="openPopu(' + i + ',' + type + ',' + DataArr + ')">';
				} else if (type == 1) {//进行中
					status = '进行中';
					delethtml = '<img class="popu_img" src="../../image/icon_bewrite_down.png" onclick="openPopu(' + i + ',' + type + ',' + DataArr + ')">';
				} else if (type == 2) {//结束
					status = '已关闭';
					delethtml = '<p class="mui-ellipsis base_grey content_p right-tag  font12">' + data.num + '/' + data.countnum + '提交' + '</p>'
				}
//				var htmls = '<li class="mui-table-view-cell mui-media" where_type="' + data.status + '"  id="' + data.id + '"  onclick="openwin(this,' + DataArr + ')">' 
//				           + '<a href="javascript:;">' 
//				           + '<img class="mui-media-object mui-pull-left" src="../../image/icon_qiandao_.png" >' 
//				           + '<div class="mui-media-body">' 
//				           + '<div class="right-div">' 
//				           + '<div class="discuss-del-div">' + delethtml + '</div>' 
//				           + '<p class="mui-ellipsis base_grey content_p right-tag font12" id="status_div">' + status + '</p>' 
//				           + '</div>' 
//				           + '<div class="left-div">' 
//				           + '<p class="mui-ellipsis base_dark_grey font14 cell-title">' 
//				           + '<span class="message_title">' + name + '</span>' 
//				           + '</p>' 
////				           + '<p class="mui-ellipsis base_grey font12 content_p cell-subtitle">' + classname + '</p>' 
//				           + '<p class="mui-ellipsis base_grey font12 content_p cell-subtitle">' 
//				           + '<span class="file_submit_time">' + timeWithStamp3(data.createtime) + '</span>' 
//				           + '</p>' + '</div>' + '</div>' + '</a>' + '</li>';
				           
				var htmls = '<li class="mui-table-view-cell mui-media" where_type="' + data.status + '"  id="' + data.id + '"  onclick="openwin(this,' + DataArr + ')">' 
				      + '<a  href="javascript:;">' 
				      + '<img class="mui-media-object mui-pull-left" src="../../image/icon_qiandao_.png" >' 
				      + '<div class="mui-media-body">' 
				      + '<div class="right-div">' 
				      + '<div class="discuss-del-div">' 
				      + delethtml 
				      + '</div>' 
				      + '<p class="mui-ellipsis base_grey content_p right-tag  font12  ">' 
				      + status + '</p>' 
				      + '</div>' 
				      + '<div class="left-div">' 
				      + '<p class="mui-ellipsis base_dark_grey font14 cell-title">' 
				      + '<span class="message_title">' + name + '</span>' 
				      + '</p>' 
				      + '<p class="mui-ellipsis base_grey font14 content_p cell-subtitle">' 
				      + '<span class="file_submit_time">' + timeWithStamp3(data.createtime) + '</span>' 
				      + '</p>' 
				      + '</div>' 
				      + '</div>' 
				      + '</a>' 
				      + '</li>';           
				writelist += htmls;
			}
			if (page == 1) {
				$('#SignList').html(writelist);
			} else {
				$('#SignList').append(writelist);
			}
		}

		function deletquestion(id) {
			//			event.stopPropagation();
			$("#logout").show();
			tid = id;
		}

		//单条数据刷新
		function itemRefresh(i, type, data) {
			var status = "";
			var delethtml = "";
			var id = data.id;
			var DataArr = JSON.stringify(data).replace(/"/g, '&quot;');
			if (type == 0) {//未开始
				status = '未开始';
				delethtml = '<img class="popu_img" src="../../image/icon_bewrite_down.png" onclick="openPopu(' + i + ',' + type + ',' + DataArr + ')">';
			} else if (type == 1) {//进行中
				status = '进行中';
				delethtml = '<img class="popu_img" src="../../image/icon_bewrite_down.png" onclick="openPopu(' + i + ',' + type + ',' + DataArr + ')">';
			} else if (type == 2) {//结束
				status = '已关闭';
				delethtml = '<p class="mui-ellipsis base_grey content_p right-tag  font12">' + data.num + '/' + data.countnum + '提交' + '</p>'
			}
			$('#' + id).find('p').eq(0).html('');
			$('#' + id).find('.discuss-del-div').html('');
			$('#' + id).find('p').eq(0).html(status);
			$('#' + id).find('.discuss-del-div').html(delethtml);
			$('#' + id).attr("where_type", type);
		}

		//取消
		function cancel() {
			$("#logout").hide();
		}

		//确定
		function confirm() {
			delet();
			$("#logout").hide();
		}

		function openPopu(i, type, data) {
			event.stopPropagation();
			if ($(".popu_img").eq(i).attr("src") == "../../image/icon_bewrite_down.png") {
				$(".popu_img").eq(i).attr("src", "../../image/icon_bewrite_up.png");
			} else {
				$(".popu_img").eq(i).attr("src", "../../image/icon_bewrite_down.png");
			}
			var pTag1 = new Object();
			var pTag2 = new Object();
			var pTag3 = new Object();
			if (type == 0) {//未开始
				pTag3 = {
					imgUrl : '../../image/icon_activity_start.png',
					title : '开始'
				}
			} else if (type == 1) {//进行中
				pTag1 = {
					imgUrl : '../../image/icon_activity_del_disabled.png',
					title : '删除',
					textcolor : '#999999'
				}
				pTag2 = {
					imgUrl : '../../image/icon_activity_edit_disabled.png',
					title : '编辑',
					textcolor : '#999999'
				}
				pTag3 = {
					imgUrl : '../../image/icon_activity_end.png',
					title : '结束'
				}
			} else if (type == 2) {
				pTag1 = {
					imgUrl : '../../image/icon_activity_del_disabled.png',
					title : '删除',
					textcolor : '#999999'
				}
				pTag2 = {
					imgUrl : '../../image/icon_activity_edit_disabled.png',
					title : '编辑',
					textcolor : '#999999'
				}
				pTag3 = {
					imgUrl : '../../image/icon_activity_end.png',
					title : '已结束'
				}
			}
			/*
			 * @param topTitle标题
			 * @param pTag1标签1 不传显示默认
			 * @param pTag2标签2 不传显示默认
			 * @param pTag3标签3 不传显示默认
			 * @param imgUrl图片路径
			 * @param title标签名称
			 *  return tag 0点击背景 1点击tag1 2点击tag2 3点击tag3 4点击取消*/
			var popup = new activityBottomPopupObjc();
			popup.openBottomPopup({
				topTitle : data.name,
				pTag1 : pTag1,
				pTag2 : pTag2,
				pTag3 : pTag3
			}, function(tag) {
				//				alert(tag);
				JudgeTypeOpen(i, tag, type, data)
				popup.closeBottomPopup();
			});
		}

		function JudgeTypeOpen(i, tag, type, data) {
			switch(tag) {
				case 1:
					if (type == 0) {//未开始状态才可删除
						deletquestion(data.id)
					}
					break;
				case 2:
					if (type == 0) {//未开始
						Editwin(data.id);
					}
					break;
				case 3:
					if (type == 0) {
						actionDosign(i, "start", data);
					} else if (type == 1) {
						actionDosign(i, "end", data);
					}
					break;
				default:
			}
			if ($(".popu_img").eq(i).attr("src") == "../../image/icon_bewrite_down.png") {
				$(".popu_img").eq(i).attr("src", "../../image/icon_bewrite_up.png");
			} else {
				$(".popu_img").eq(i).attr("src", "../../image/icon_bewrite_down.png");
			}
		}

		/**
		 *签到、提问开始、结束接口
		 *
		 *uid     :用户id
		 jid     :集团id
		 iid      互动id
		 tid       互动类型id 1:签到   2：提问  3：调查  4：讨论
		 action      操作（start、<end></end>）
		 cid        课程id
		 *  */
		function actionDosign(i, action, Arrdata) {
			var params = {
				jid : $api.getStorage('cfnetppjxid'),
				uid : $api.getStorage('cfnetppuid'),
				iid : Arrdata.id,
				tid : 1,
				action : action
			}
			var actionStr = action == 'start' ? '开启' : '关闭';
			var typeStr = action == 'start' ? '1' : '2';
			cfnetppPOST(url_actionDosign, params, true, function(data, status) {
				if (action == 'start') {
					SendBusinessOperationsLogNotifi('老师端签到开启', '193', params, params, '', data, '老师端签到开启接口 ', '193-01')
				} else {
					SendBusinessOperationsLogNotifi('老师端签到结束', '193', params, params, '', data, '老师端签到结束接口  ', '193-03')
				}
				api.hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						itemRefresh(i, typeStr, Arrdata)
					}else if(data.code==103){
					   ShowToast('其它终端正在使用,无法'+actionStr);	
					} else {
						ShowToast(actionStr + '失败');
					}
				}else{
				   ShowToast(actionStr + '失败');
				}
			})
		}

		//删除
		function delet() {
			var params = {
				aid : tid,
				jid : $api.getStorage('cfnetppjxid'),
				uid : $api.getStorage('cfnetppuid'),
			}
			cfnetppPOST(url_Delactive, params, true, function(data, status) {
				SendBusinessOperationsLogNotifi('老师端签到删除', '193', params, params, '', data, '老师端签到删除接口  ', '193-02')
				api.hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						$('#' + tid).remove();
						if($('#SignList').html() == ''){
							$('#noNet').hide();
							$('#noData').show();
							$('#mian').hide();
						}
					}
				}
			})
		}

		//获取当前签到活动状态，避免与pc状态冲突
		function getActiveStatus(type, datas) {
		
			var params = {
				iid : datas.id,
				source : 1,
			}
			cfnetppPOST(url_getActiveSourceConductStatus, params, false, function(data, status) {
			
				if (status == 'success') {
					if (data.code == 200) {
						judgeTypeOpenWin(type, datas)
					} else {
						ShowToast(data.message)
					}
				} else {
					ShowToast(data.message)
				}
			})
		}

		//打开页面
		function openwin(obj, data) {
//			var item = data;
			//1是进行中，2是关闭，0就是未开始
			var type = $(obj).attr("where_type");
			getActiveStatus(type, data);
		}

		function judgeTypeOpenWin(type, data) {
			var item = data;
			if (type == 0) {
				Editwin(data.id)
			} else if (type == 1) {
				api.openWin({useWKWebView:true,
					name : 'Teacher_SigningFrame',
					url : 'Teacher_SigningFrame.html',
					pageParam : {
						type : 1,
						id : data.id,
						item : item,
						cid : api.pageParam.cid,
						pid : api.pageParam.pid,
						islist : true,
						sourceurl : api.pageParam.sourceurl,
						sourcetitle : api.pageParam.sourcetitle
					},
					slidBackEnabled : false,
				});
			} else {//详情
				api.openWin({useWKWebView:true,
					name : 'TeacherSignDetailWindow',
					url : 'TeacherSignDetailWindow.html',
					pageParam : {
						type : 1,
						id : data.id,
						item : item,
						cid : api.pageParam.cid,
						pid : api.pageParam.pid,
						sourceurl : api.pageParam.sourceurl,
						sourcetitle : api.pageParam.sourcetitle
					},
				});
			}
		}

		function Editwin(id) {
			api.openWin({useWKWebView:true,
				name : 'TeacherSignEditorFrame',
				url : 'TeacherSignEditorFrame.html',
				pageParam : {
					type : 1,
					id : id,
					cid : api.pageParam.cid,
					pid : api.pageParam.pid,
					sourceurl : api.pageParam.sourceurl,
					sourcetitle : api.pageParam.sourcetitle
				},
				slidBackEnabled : false,
			});
		}
	</script>
</html>